package pl.edu.pw.stud.ltrzaska.policy.xml;

import pl.edu.pw.stud.ltrzaska.policy.entity.Sequence;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;

public class SequenceConverter extends DirectoryConverter implements Converter {

	@Override
	public boolean canConvert(Class clazz) {
		return clazz.equals(Sequence.class);
	}
	

	@Override
	public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
		Sequence sequence = new Sequence();

		ConverterCommons.preLoopUnmarshal(reader, sequence);
		while (reader.hasMoreChildren()) {
			reader.moveDown();
			String attrName = reader.getNodeName();

			ConverterCommons.inLoopUnmarshal(reader, context, sequence);
			reader.moveUp();
		}
		return sequence;
	}
}
